home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / lightwave / arexx_macros / seq.arexx < prev    next >
Internet Message Format  |  1996-12-09  |  6KB

  1. From shf@well.sf.ca.us  Ukn Aug  1 01:14:30 1993
  2. Received: from bobsbox.rent.com by rutgers.edu (5.59/SMI4.0/RU1.5/3.08) with UUCP 
  3.     id AA10001; Sun, 1 Aug 93 01:42:44 EDT
  4. Received: by bobsbox.rent.com (V1.16/Amiga)
  5.     id AA02lya; Sun, 1 Aug 93 01:26:23 EDT
  6. Received: from nkosi.well.sf.ca.us by rutgers.edu (5.59/SMI4.0/RU1.5/3.08) 
  7.     id AA04395; Sun, 1 Aug 93 01:10:33 EDT
  8. Received: from well.sf.ca.us (well.sf.ca.us [192.132.30.2]) by nkosi.well.sf.ca.us (8.5/8.5) with SMTP id WAA16226; Sat, 31 Jul 1993 22:10:30 -0700
  9. Received: by well.sf.ca.us id <13989-1>; Sat, 31 Jul 1993 22:10:09 -0700
  10. Message-Id: <93Jul31.221009pdt.13989-1@well.sf.ca.us>
  11. Date:     Sat, 31 Jul 1993 22:10:05 -0700
  12. From: "Stuart H. Ferguson" <shf@well.sf.ca.us>
  13. To: lightwave@bobsbox.rent.com
  14. Subject: Useful ARexx Script for Sequences
  15. Status: RO
  16. X-Status: 
  17.  
  18. If you find yourself manipulating image sequences as much as I do, you
  19. may find this little ARexx script useful.  It is used as a shell command
  20. preprocessor and allows any shell command to be invoked iteratively on
  21. a series of images.  This makes it easy to do things like:
  22.  
  23.     Delete images MyFG001 through MyFG030 ...
  24.     cli> seq delete MyFG#30#
  25.  
  26.     Delete every other image from Imgs001 - Imgs020 ...
  27.     cli> seq delete Imgs#2,20,2#
  28.  
  29.     Rename the remaining images as NewSeq001 - NewSeq010 ...
  30.     cli> seq rename Imgs#1,20,2# NewSeq#
  31.  
  32. Have fun ...
  33.  
  34.         Stuart Ferguson        (shf@well.sf.ca.us)
  35.             Prepare to Surge to Sublight Speed!
  36. ----------------
  37.  
  38. /*
  39.  * SEQ -- Command Sequence Processor
  40.  *
  41.  * This takes a shell command with special pattern codes embedded in it
  42.  * and issues a sequence of shell commands generated by filling in the
  43.  * patterns.  This allows for one-line processing of a sequence of files
  44.  * such as LightWave image sequences.
  45.  *
  46.  * Some examples:
  47.  *
  48.  *    CLI> seq copy abc#30# abc#.bku
  49.  *    copy abc001 abc001.bku
  50.  *    copy abc002 abc002.bku
  51.  *     ...
  52.  *    copy abc030 abc030.bku
  53.  *
  54.  *    CLI> seq rename img#1,20,2# ximg#3,10#
  55.  *    rename img001 ximg003
  56.  *    rename img003 ximg004
  57.  *    rename img005 ximg005
  58.  *     ...
  59.  *    rename img017 ximg011
  60.  *    rename img019 ximg012
  61.  *
  62.  * It takes the command line and breaks it up into words.  Each word
  63.  * can contain a sequence pattern which will be expanded into a sequence
  64.  * of words with numbers replacing the pattern code.  The codes can be
  65.  * in the following forms:
  66.  *
  67.  *      pattern form          start    end     step
  68.  *      ------------          -----    ---     ----
  69.  *     #            1    1    1
  70.  *     #N#            1    N    1
  71.  *     #K,N#            K    N    1
  72.  *     #K,N,S#        K    N    S
  73.  *
  74.  * Any word without a pattern is just a constant which gets repeated
  75.  * in each iteration.  The total number of iterations for the combined
  76.  * command is the MAXIMUM number of elements in any sequence.
  77.  *
  78.  * If the command line is preceded by a hyphen (i.e. "seq -copy ..."),
  79.  * the commands will be generated and displayed but not envoked as
  80.  * shell commands.  This allows you to test a complex pattern before
  81.  * letting it work on real files.
  82.  *
  83.  * This should be placed in the "S:" directory and have its script bit
  84.  * set to work as indicated in the above examples.
  85.  *
  86.  * 7/93        Stuart Ferguson
  87.  */
  88.  
  89.  
  90. call addlib("rexxsupport.library",0,-30,0)
  91.  
  92. /* Get command line from shell.
  93.  */
  94. parse arg cmdline
  95.  
  96. /* Look for leading hyphen to see if this is a real command.
  97.  */
  98. forreal = 1
  99. cmdline = strip(cmdline)
  100. if (left(cmdline, 1) = '-') then do
  101.     forreal = 0
  102.     cmdline = strip(substr(cmdline,2))
  103. end
  104.  
  105. /* Get number of words on command line.
  106.  */
  107. narg = words(cmdline)
  108. if (narg < 1) then exit 10
  109.  
  110. /* Convert each word into sequence form and get the max sequence size
  111.  * as the number of iterations.
  112.  */
  113. iter = 1
  114. do i=1 to narg
  115.     templ.i = namebreak(word(cmdline,i))
  116.     iter = max(iter, namecount(templ.i))
  117. end i
  118.  
  119. /* Generate a new command line by expanding each sequence pattern into
  120.  * a specific instance for each iteration.
  121.  */
  122. do k=1 to iter
  123.     cmd = ""
  124.     do i=1 to narg
  125.     cmd = cmd || iname(k,templ.i) || ' '
  126.     end i
  127.  
  128.     say cmd
  129.     if (forreal) then address command cmd
  130. end k
  131.  
  132. exit
  133.  
  134.  
  135.  
  136. /*
  137.  * NameBreak converts a pattern word into a sequence descriptor.  The
  138.  * descriptor consists of five words: name pattern, number of digits,
  139.  * start index, step, end index.  Pattern is a word with a '*' in it
  140.  * where the number will go.
  141.  */
  142. NAMEBREAK: procedure
  143.     parse arg name
  144.  
  145.     /* Find first pattern marker.  If none, this is a constant sequence.
  146.      */
  147.     p1 = pos('#',name)
  148.     if (p1 = 0) then return name || "* 0 1 1 1"
  149.  
  150.     /* Find second pattern marker, if any.
  151.      */
  152.     p2 = pos('#',name,p1+1)
  153.     if (p2 = 0) then p2 = p1
  154.  
  155.     /* Split out head and tail sections.  If no second pattern marker,
  156.      * just set defaults.
  157.      */
  158.     head = substr(name,1,p1-1)
  159.     tail = substr(name,p2+1)
  160.     pat = head || "*" || tail
  161.     if (p1 = p2) then return pat 3 1 1 1
  162.  
  163.     /* Parse sequence numbers.  Step defaults to 1.  Start defaults to 1.
  164.      */
  165.     larg = substr(name,p1+1,p2-p1-1)
  166.     parse var larg n0 ',' n1 ',' step
  167.     if (step = "") then step = 1
  168.     if (n1 = "") then do
  169.     n1 = n0
  170.     n0 = 1
  171.     end
  172.  
  173.     return pat 3 n0 step n1
  174.  
  175.  
  176. /*
  177.  * NameCount takes a sequence descriptor and returns the number of elements
  178.  * defined by the sequence.
  179.  */
  180. NAMECOUNT: procedure
  181.     arg pat ndig n0 step n1 .
  182.     return (n1 - n0 + step) % step
  183.  
  184.  
  185. /*
  186.  * IName takes an index and sequence descriptor and returns the name 
  187.  * generated for the given index.
  188.  */
  189. INAME: procedure
  190.     parse arg i, pat ndig n0 step .
  191.     parse var pat head '*' tail
  192.     num = right(n0 + step * (i - 1), ndig, 0)
  193.     return head || num || tail
  194.  
  195. ----------------- end --------------
  196.  
  197.  
  198.